<?php

require_once dirname(__FILE__)."/../common/xmlFile.php";
require_once "stockData.php";
require_once "providerQuery.php";

abstract class Provider{
	//protected $xmlDescription;
	protected $name;
	protected $type;
	protected $map;
	protected $rank;
	public static $TYPE_SINGLETICK = 0;
	public static $TYPE_CONDENSEDTICK = 1;
	
	//se $_rank = 0 ==> rank automatico
	public function __construct($_name, $_type, $_map, $_rank = 0){
		$this->name = $_name;
		$this->type = $_type;
		if(isset($_map))
			$this->map = $_map;
		else
			$this->CreateMap();
		$this->rank = $_rank;
	}
	
	abstract protected function CreateMap();
	
	public function GetName(){
		return $this->name;
	}

	public function GetType(){
		return $this->type;
	}
	
	public function GetMap(){
		return $this->map;
	}
	
	public function GetRank(){
		return $this->rank;
	}
	
	public function Generate($assocArrayStockData){
		return $this->map->Generate($assocArrayStockData);
	}
	
	abstract function Query($ticker, $ts);	//deve restituire NULL se non ci sono dati disponibili per il timestamp selezionato
}

class Map{
	private $dateTime;
	private $volume;
	private $close;
	private $open;
	private $low;
	private $high;
	
	public function __construct($dateTime, $volume, $close, $open = NULL, $low = NULL, $high = NULL){
		$this->dateTime = $dateTime;
		$this->volume = $volume;
		$this->close = $close;
		$this->open = $open;
		$this->low = $low;
		$this->high = $high;
	}
	
	public function Generate($assocArrayStockData){
		$newStockData;
		
		if(isset($this->open) && isset($this->low) && isset($this->high)){
			$newStockData = new stockDataEx($assocArrayStockData[$this->dateTime],
											$assocArrayStockData[$this->open],
											$assocArrayStockData[$this->close], 
											$assocArrayStockData[$this->low],
											$assocArrayStockData[$this->high],
											$assocArrayStockData[$this->volume]);
		}
		else
			$newStockData = new stockData(	$assocArrayStockData[$this->dateTime],
											$assocArrayStockData[$this->close],
											$assocArrayStockData[$this->volume]);

		return $newStockData;
	}
}

?>
	